package com.yinhai.cp_nzw.controller;

import com.yinhai.cp_nzw.bean.CP;
import com.yinhai.cp_nzw.service.IndexService;
import com.yinhai.cp_nzw.utils.GenerateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    IndexService indexService;

    @RequestMapping("/")
    public String execute(Model model) {
        return "index";
    }

    @RequestMapping("/generateCode")
    @ResponseBody
    public CP generateCode() {
        CP cp = GenerateCode.gCode();
        int result = indexService.saveCode(cp);
        if (result > 0) {
            return cp;
        }
        return null;
    }

    /**
     * 统计蓝球的出现次数
     * @return
     */
    @RequestMapping("/statisticsBlue")
    @ResponseBody
    public List<Map<String, Object>> statisticsBlue() {
        List<Map<String, Object>> blue = indexService.statisticsBlue();
        return blue;
    }
}
